import { Component, ViewChild } from "@angular/core";
import {
  IonicPage,
  NavController,
  NavParams,
  Slides,
  ToastController
} from "ionic-angular";
import { TeamDetailsPage } from "../td/team-details/team-details";
import { TeamSeriveProvider } from "../../../providers/team-serive/team-serive";
import { BaseUI } from "../../../common/baseUI";
/**
 * Generated class for the TdPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: "page-td",
  templateUrl: "td.html"
})
export class TdPage extends BaseUI {
  teamDatas: Array<any> = [];
  //轮播图
  @ViewChild(Slides) slides: Slides;
  //当前选中第几个 默认0
  tabsActiveIndex = 0;

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public teamSeriveProvider: TeamSeriveProvider,
    public toastCtrl: ToastController
  ) {
    super();
    this.teamDatas = [
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      },
      {
        imgUrl:
          "https://ionicframework.com/dist/preview-app/www/assets/img/card-sf.png",
        teamName: "团队",
        number: "46"
      }
    ];
  }

  ionViewDidLoad() {
    this.init();
  }

  init() {
    // this.teamSeriveProvider.login("123", "13229677964").subscribe(data => {
    //   if (data.msg == "OK" && data.status == 200) {
        // this.teamSeriveProvider.isLogin(data.data).subscribe(status => {
        //   if (status["msg"] == "OK" && status["status"] == 200) {
            this.getJoinTeam("1f51380a-e763-49fa-8260-122b768c3067");
            // return;
        //   }
        //   super.showToast(this.toastCtrl, "登录验证失败");
        // });
      // } else {
      //   super.showToast(this.toastCtrl, "1");
      // }
    // });
  }
  
  //调用接口的请求获取 
  getJoinTeam(token) {
    this.teamSeriveProvider.getTeamDetails(1, token).subscribe(data => {
      // if (data != null) {
      //   if (data.status != 500) return;
      //   super.showToast(this.toastCtrl, "登录失效，请重新登录");
      // }
    });
  }

  //滑动切换触发
  changeSelect() {
    this.tabsActiveIndex = this.slides.getActiveIndex();
    if (this.tabsActiveIndex > 1) this.tabsActiveIndex = 1;
  }

  openTeamDetail() {
    this.navCtrl.push("TeamDetailsPage");
  }
}
